package com.shopx.cm.controller;

import com.shopx.base.anno.ShopxCheckParamAnno;
import com.shopx.cm.bean.MaterialSaleDTO;
import com.shopx.cm.bean.MaterialSaleReqDTO;
import lombok.extern.slf4j.Slf4j;
import com.shopx.base.anno.ShopxParamAnno;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shopx.base.controller.BaseController;

import javax.annotation.Resource;

import com.shopx.cmm.DTO.PageDTO;
import com.shopx.base.dto.Result;
import com.shopx.base.utils.ResultUtil;
import com.shopx.base.exception.ShopxException;
import com.shopx.cm.bean.CmSaleDetail;
import com.shopx.cm.model.CmSaleDetailModel;
import com.shopx.cm.service.ICmSaleDetailService;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.core.common.CommonConstant;

import java.util.List;

/**
 * TODO
 *
 * @author lituo
 * @className: CmSaleDetailController
 * @date 2025-03-05
 */
@RestController
@Slf4j
@RequestMapping(value = "/cmSaleDetail")
public class CmSaleDetailController extends BaseController {

    @Resource
    private ICmSaleDetailService cmSaleDetailService;

    @PostMapping(value = "/queryPageList")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> queryPageList(@RequestBody CmSaleDetailModel cmSaleDetail) throws ShopxException {
        PageDTO<CmSaleDetailModel> pageDTO = cmSaleDetailService.getListPage(cmSaleDetail);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/insertOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> insertOne(@RequestBody CmSaleDetail cmSaleDetail) throws ShopxException {
        int result = cmSaleDetailService.insertSelective(cmSaleDetail);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/updateOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> updateOne(@RequestBody CmSaleDetail cmSaleDetail) throws ShopxException {
        int result = cmSaleDetailService.updateByPrimaryKeySelective(cmSaleDetail);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/queryOneByPrimaryKey")
    public Result<CmSaleDetailModel> queryOneByPrimaryKey(@RequestBody CmSaleDetail cmSaleDetail) throws ShopxException {
        CmSaleDetailModel result = cmSaleDetailService.selectByPrimaryKey(cmSaleDetail);
        return ResultUtil.ok(result);
    }


    /**
     * 材料销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByMaterial")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByMaterial(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = cmSaleDetailService.getSalesByMaterial(dto);
        return ResultUtil.ok(pageDTO);
    }


    /**
     * 根据分组查询
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/querySalesByGroupList")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<MaterialSaleDTO> querySalesByGroupList(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        List<MaterialSaleDTO> list = cmSaleDetailService.querySalesByGroupList(dto);
        return ResultUtil.ok(list);
    }

    /**
     * 材料品牌销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByBrand")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByBrand(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = cmSaleDetailService.getSalesByBrand(dto);
        return ResultUtil.ok(pageDTO);
    }


    /**
     * 材料实付销售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByCode")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByCode(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = cmSaleDetailService.getSalesByCode(dto);
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 材料月度售数据统计
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByMth")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> getSalesByMth(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = cmSaleDetailService.getSalesByMth(dto);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/querySalesListByCode")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> querySalesListByCode(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        List<MaterialSaleDTO> list = cmSaleDetailService.querySalesListByCode(dto);
        return ResultUtil.ok(list);
    }


    /**
     * 品牌大区店铺排名
     * @param dto
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/getSalesByBrsList")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<MaterialSaleDTO> getSalesByBrsList(@RequestBody MaterialSaleReqDTO dto) throws ShopxException {
        PageDTO<MaterialSaleDTO> pageDTO = cmSaleDetailService.getSalesByBrsList(dto);
        return ResultUtil.ok(pageDTO);
    }

	/*@PostMapping(value = "/deleteChecked")
	@RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
					@ShopxParamAnno
public Result<Integer> deleteChecked(@RequestBody CmSaleDetail cmSaleDetail) throws ShopxException {
		int result = cmSaleDetailService.deleteByPrimaryKey(cmSaleDetail);
		return ResultUtil.ok(result);
	}*/
}

